package com.cn.ccp.action.classschedule.user;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.apache.log4j.Logger;

import com.cn.ccp.action.BaseAction;
import com.cn.ccp.bean.ClassScheduleDetailBean;
import com.cn.ccp.bean.ClassScheduleSettingsBean;
import com.cn.ccp.bean.GradeBean;
import com.cn.ccp.bean.TermSettingBean;
import com.cn.ccp.bean.UserBean;
import com.cn.ccp.util.CCPContants;
import com.cn.ccp.util.Contants;
import com.cn.ccp.util.MsgConstants;

/**
 * 学生或老师课程表
 * 只做显示
 * @author renyongchengO
 *O
 */
public class ClassScheduleDetailForUserAction extends BaseAction{
	private Logger log = Logger.getLogger(ClassScheduleDetailForUserAction.class);
	private ClassScheduleDetailBean bean;
	private String gradeName;//班级名称
	private String weekSchedule;//一周课程表
	private String daySchedule;//当天课程表
	
    public ClassScheduleDetailForUserAction(){
    	UserBean userBean = CCPContants.getUserBean();
    	log.info("============"+userBean);
    	log.info("userBean.getGrade() = "+userBean.getGrade());
    	if(userBean.getGrade() != null && !"".equalsIgnoreCase(userBean.getGrade()) &&  !"-1".equalsIgnoreCase(userBean.getGrade()))
    		initSchedule(userBean.getGrade());
    }
    	 
	private void initSchedule(String gradeId){
		
		log.info("=============gradeId = "+gradeId);
		Calendar cur = Calendar.getInstance();
		int dayForWeek;
		if(cur.get(Calendar.DAY_OF_WEEK) == 1){  
			 dayForWeek = 7;  
		 }else{  
			 dayForWeek = cur.get(Calendar.DAY_OF_WEEK) - 1;  
		 }  
		int curYear = cur.get(Calendar.YEAR);
		List termSetList =  getTermSettingService().queryTerymByYear(curYear) ;
		if(termSetList == null){
			log.warn("Has been not setting class schudule..");
			//
			return;
		}
		int count = termSetList.size();
		TermSettingBean termSettingBean ,curTermSettingBean = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		for(int i =0; i<count; i++){
			termSettingBean = (TermSettingBean)termSetList.get(i);
			Calendar cal = Calendar.getInstance();
			try {
				cal.setTime(sdf.parse(termSettingBean.getFirstWeekStart()));
			} catch (ParseException e) {
				log.error("format data failed : ", e);
			}
			log.info(termSettingBean);
			int value = cal.compareTo(cur) ;
			log.info("------value = "+value);
			if(value == -1)//cal 比 cur 早
				curTermSettingBean = termSettingBean;
		}
		
		if(curTermSettingBean == null){
			log.warn("Has been not setting class schudule..");
			initNoSetting();
			return ;
		}
		log.info("-------------"+curTermSettingBean.getId()+":"+gradeId);
		GradeBean gradeBean = (GradeBean)getGradeService().findGradeById(Integer.parseInt(gradeId));
		gradeName = gradeBean.getGradeType();
		List<ClassScheduleDetailBean> allList = getClassScheduleDetailService().pageQueryForUserByGradeId(gradeId,curTermSettingBean.getId());//返回系统课程表
    	count = allList.size();
    	log.info("=============:count = "+count);
    	ClassScheduleDetailBean bean;
    	
    	StringBuffer buf = new StringBuffer();
    	buf.append("<table class='table table-bordered table-striped tab-b'>");
    	buf.append("<thead>");
    	buf.append("<tr>");
		buf.append("<th class='col-odd'>&nbsp;</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_MONDAY)+"</th>");
		buf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_TUESDAY)+"</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_WEDNESDAY)+"</th>");
		buf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_THURSDAY)+"</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_FRIDAY)+"</th>");
		buf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SATURDAY)+"</th>");
		buf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SUNDAY)+"</th>");
    	buf.append("</tr>");
    	buf.append("</thead>");
    	
    	ArrayList<String> moningList = new ArrayList<String>();//早上课程表list
    	ArrayList<String> noonList = new ArrayList<String>();//上午课程表list
    	ArrayList<String> afterNoonList = new ArrayList<String>();//下午课程表list
    	ArrayList<String> nightList = new ArrayList<String>();//晚上课程表list
    	
    	ArrayList<String> dayMoningList = new ArrayList<String>();//早上课程表list
    	ArrayList<String> dayNoonList = new ArrayList<String>();//上午课程表list
    	ArrayList<String> dayAfterNoonList = new ArrayList<String>();//下午课程表list
    	ArrayList<String> dayNightList = new ArrayList<String>();//晚上课程表list
    	int num = 1;
    	
    	StringBuffer temp = new StringBuffer();
    	for(int i=0; i<count; i++){
    		bean = allList.get(i);
    		if(bean.getWeek() == 1){
				temp.append("<td class='col2'>");
			}else{
				temp.append("<td>");
			}
//    		temp.append("<a href = 'editScheduleDetail.faces?id="+bean.getId()+"'>");
			temp.append(Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects()) ? "&nbsp;":bean.getSubjects());
//			temp.append("</a>");
			temp.append("<br/>");
			if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects())){
				temp.append("<i class='n14-icon-map-marker'></i>");
				temp.append(bean.getClassAddress().length() > 8 ? bean.getClassAddress().substring(0,8)+"..." : bean.getClassAddress());
				temp.append("<br/>");
				temp.append(bean.getStartTime());
				temp.append("-");
				temp.append(bean.getEndTime());
				temp.append("<br/>");
				temp.append("<i class='n14-icon-calendar'></i>");
				temp.append(bean.getStartWeek());
				temp.append("-");
				temp.append(bean.getEndWeek());
				temp.append(getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
			}
			temp.append("</td>");
    		switch(bean.getScheduleType()){
				case Contants.SCHEDULE_TYPE_MORNING:
					if(bean.getWeek() == 7){
						moningList.add(temp.toString());
						temp = new StringBuffer();
					}
					if(bean.getWeek() == dayForWeek){
						if(num % 2== 0){
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayMoningList.add("<td class='block-w' width='153px'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayMoningList.add("<td class='block-w' width='153px'></td><td>&nbsp;</td>");
						}else{
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayMoningList.add("<td class='block-b' width='153px'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayMoningList.add("<td class='block-b' width='153px'></td><td>&nbsp;</td>");
						}	
					}
					break;
				case Contants.SCHEDULE_TYPE_FORENOON:
					if(bean.getWeek() == 7){
						noonList.add(temp.toString());
						temp = new StringBuffer();
					}
					if(bean.getWeek() == dayForWeek){
						if(num % 2== 0){
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayNoonList.add("<td class='block-w'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayNoonList.add("<td class='block-w'></td><td>&nbsp;</td>");
						}else{
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayNoonList.add("<td class='block-b'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayNoonList.add("<td class='block-b'> </td><td>&nbsp;</td>");
						}
					}
					break;
				case Contants.SCHEDULE_TYPE_AFTERNOON:
					if(bean.getWeek() == 7){
						afterNoonList.add(temp.toString());
						temp = new StringBuffer();
					}
					if(bean.getWeek() == dayForWeek){
						if(num % 2== 0){
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayAfterNoonList.add("<td class='block-w'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayAfterNoonList.add("<td class='block-w'> </td><td>&nbsp;</td>");
						}else{
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayAfterNoonList.add("<td class='block-b'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayAfterNoonList.add("<td class='block-b'> </td><td>&nbsp;</td>");
						}
					}
					break;
				case Contants.SCHEDULE_TYPE_NIGHT:
					if(bean.getWeek() == 7){
						nightList.add(temp.toString());
						temp = new StringBuffer();
					}
					if(bean.getWeek() == dayForWeek){
						if(num % 2== 0){
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayNightList.add("<td class='block-w'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayNightList.add("<td class='block-w'> </td><td>&nbsp;</td>");
						}else{
							if(!Contants.SCHEDULE_CLASS_SUBJECT_INIT.equalsIgnoreCase(bean.getSubjects().trim()))
								dayNightList.add("<td class='block-b'>"+bean.getSubjects()+"</td><td><i class='n14-icon-map-marker'></i> "+bean.getClassAddress()+"&nbsp;&nbsp;<i class='n14-icon-time'></i>"+bean.getStartTime()+"-"+bean.getEndTime()+"&nbsp;&nbsp;<i class='n14-icon-calendar'></i>"+bean.getStartWeek()+"-"+bean.getEndWeek()+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_UNIT));
							else
								dayNightList.add("<td class='block-b'> </td><td>&nbsp;</td>");
						}
					}
					break;
			}
    		num++;
    	}
    	
    	
    	//设置早上课程表
    	count = moningList.size();
    	for(int i=0; i<count; i++){
    		buf.append("<tr>");
    		if(i==0){
    			if(count >1)
	    			buf.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
	    		else if(count == 1)
	    			buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    		}
    		buf.append(moningList.get(i));
    		buf.append("</tr>");
    	}
    	
    	//设置上午课程表
    	count = noonList.size();
    	for(int i=0; i<count; i++){
    		buf.append("<tr>");
    		if(i==0){
    			if(count >1)
	    			buf.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
	    		else if(count == 1)
	    			buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    		}
    		buf.append(noonList.get(i));
    		buf.append("</tr>");
    	}
    	
    	//设置下午课程表
    	count = afterNoonList.size();
    	for(int i=0; i<count; i++){
    		buf.append("<tr>");
    		if(i==0){
    			if(count >1)
	    			buf.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
	    		else if(count == 1)
	    			buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    		}
    		buf.append(afterNoonList.get(i));
    		buf.append("</tr>");
    	}
    	
    	//设置晚上课程表
    	count = nightList.size();
    	for(int i=0; i<count; i++){
    		buf.append("<tr>");
    		if(i==0){
    			if(count >1)
	    			buf.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
	    		else if(count == 1)
	    			buf.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    		}
    		buf.append(nightList.get(i));
    		buf.append("</tr>");
    	}
    	
    	buf.append("</table>");
    	weekSchedule = buf.toString();
    	
    	StringBuffer simple = new StringBuffer();//当天课程表
    	simple.append("<table class='table table-bordered table-striped tab-b'>");
    	//设置早上课程表
    	count = dayMoningList.size();
    	for(int i=0; i<count; i++){
    		simple.append("<tr>");
    		if(i==0){
    			if(count >1)
    				simple.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
	    		else if(count == 1)
	    			simple.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    		}
    		simple.append(dayMoningList.get(i));
    		simple.append("</tr>");
    	}
    	
    	//设置上午课程表
    	count = dayNoonList.size();
    	for(int i=0; i<count; i++){
    		simple.append("<tr>");
    		if(i==0){
    			if(count >1)
    				simple.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
	    		else if(count == 1)
	    			simple.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    		}
    		simple.append(dayNoonList.get(i));
    		simple.append("</tr>");
    	}
    	
    	//设置下午课程表
    	count = dayAfterNoonList.size();
    	for(int i=0; i<count; i++){
    		simple.append("<tr>");
    		if(i==0){
    			if(count >1)
    				simple.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
	    		else if(count == 1)
	    			simple.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    		}
    		simple.append(dayAfterNoonList.get(i));
    		simple.append("</tr>");
    	}
    	
    	//设置晚上课程表
    	count = dayNightList.size();
    	for(int i=0; i<count; i++){
    		simple.append("<tr>");
    		if(i==0){
    			if(count >1)
    				simple.append("<td rowspan='"+count+"'  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
	    		else if(count == 1)
	    			simple.append("<td  style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    		}
    		simple.append(dayNightList.get(i));
    		simple.append("</tr>");
    	}
    	
    	simple.append("</table>");
    	daySchedule  = simple.toString();
    	log.info("-----------daySchedule"+daySchedule);
	}
	
	
	private void initNoSetting(){
		List<ClassScheduleSettingsBean> setList = getScheduleSettingService().getSettings();
		int  moningNumber = 0,noonNumber = 0,afternoonNumber = 0 , nightNumber = 0;
		for(ClassScheduleSettingsBean b : setList){
			if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_MORNING))){
				moningNumber = b.getNumber();
			}else if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_FORENOON))){
				noonNumber = b.getNumber();
			}else if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_AFTERNOON))){
				afternoonNumber = b.getNumber();
			}else if(b.getClassScheduleType().equals(String.valueOf(Contants.SCHEDULE_TYPE_NIGHT))){
				nightNumber = b.getNumber();
			}
		}
		
		StringBuffer weekBuf = new StringBuffer();
		weekBuf.append("<table class='table table-bordered table-striped tab-b'>");
		weekBuf.append("<thead>");
		weekBuf.append("<tr>");
		weekBuf.append("<th class='col-odd'>&nbsp;</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_MONDAY)+"</th>");
		weekBuf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_TUESDAY)+"</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_WEDNESDAY)+"</th>");
		weekBuf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_THURSDAY)+"</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_FRIDAY)+"</th>");
		weekBuf.append("<th class='col-even' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SATURDAY)+"</th>");
		weekBuf.append("<th class='col-odd' style='text-align:center'>"+getMessages(MsgConstants.CLASS_SCHEDULE_PAGE_WEEK_SUNDAY)+"</th>");
		weekBuf.append("</tr>");
		weekBuf.append("</thead>");
		
		StringBuffer dayBuf = new StringBuffer();
		dayBuf.append("<table class='table table-bordered table-striped tab-b'>");
		
		//初始化早上的课程
		int count = moningNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_MORNING)+"</td>");
    			}
    		}
    		weekBuf.append(" <td   width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		
		//设置上午课程
		count = noonNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_FORENOON)+"</td>");
    			}
    		}
    		weekBuf.append(" <td   width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		
		//设置下午课程
		count = afternoonNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_AFTERNOON)+"</td>");
    			}
    		}
    		weekBuf.append(" <td   width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		
		//设置下午课程
		count = nightNumber;
		for(int i=0; i<count; i++){
			weekBuf.append("<tr>");
			dayBuf.append("<tr>");
    		if(i==0){
    			if(count >1){
    				weekBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    				dayBuf.append("<td rowspan='"+count+"'  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    			}else if(count == 1){
    				weekBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    				dayBuf.append("<td  style='text-align:center' width='90'>"+getMessages(MsgConstants.CLASS_SCHEDULE_SETTING_APGE_TIME_TYPE_NIGHT)+"</td>");
    			}
    		}
    		weekBuf.append(" <td width='153px'></td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>");
    		dayBuf.append(" <td>&nbsp;</td>");
    		weekBuf.append(" </tr>");
    		dayBuf.append(" </tr>");
    	}
		weekBuf.append(" </table>");
		dayBuf.append(" </table>");
		
		weekSchedule = weekBuf.toString();
		daySchedule = dayBuf.toString();
		log.info(weekSchedule);
		log.info(daySchedule);
	}
	
	
	

	public ClassScheduleDetailBean getBean() {
		if(bean == null)
			bean  = new ClassScheduleDetailBean();
		return bean;
	}

	public void setBean(ClassScheduleDetailBean bean) {
		this.bean = bean;
	}

	public String getGradeName() {
		return gradeName;
	}

	public void setGradeName(String gradeName) {
		this.gradeName = gradeName;
	}

	public String getWeekSchedule() {
		return weekSchedule;
	}

	public void setWeekSchedule(String weekSchedule) {
		this.weekSchedule = weekSchedule;
	}

	public String getDaySchedule() {
		return daySchedule;
	}

	public void setDaySchedule(String daySchedule) {
		this.daySchedule = daySchedule;
	}
	
	
}
